package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.business.BusinessFollowDTO;
import com.qk.dto.business.BusinessListDTO;
import com.qk.dto.business.BusinessPoolListDTO;
import com.qk.entity.Business;
import com.qk.management.aop.annotation.LogAnno;
import com.qk.management.service.BusinessService;
import com.qk.vo.business.BusinessByIdVO;
import com.qk.vo.business.BusinessListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    //公海池列表查询
    @GetMapping("/pool")
    public Result getPoolList(BusinessPoolListDTO dto) {
        PageResult<Business> pageResult=businessService.getPoolList(dto);
        return Result.success(pageResult);
    }


    //跟进商机
    @LogAnno
    @PutMapping
    public Result followBusiness(@RequestBody BusinessFollowDTO businessFollowDTO){
        businessService.followBusiness(businessFollowDTO);
        return Result.success();
    }


    //根据ID查询商机
    @GetMapping("/{id}")
    public Result getBusinessById(@PathVariable Integer id){
        BusinessByIdVO businessByIdVO = businessService.getBusinessById(id);
        return Result.success(businessByIdVO);
    }


    //转客户
    @LogAnno
    @PostMapping("/toCustomer/{id}")
    public Result toCustomer(@PathVariable Integer id){
        businessService.toCustomer(id);
        return Result.success();
    }


    //踢回公海
    @LogAnno
    @PutMapping("/back/{id}")
    public Result backToPool(@PathVariable Integer id){
        businessService.backToPool(id);
        return Result.success();
    }


    //分配商机
    @LogAnno
    @PutMapping("/assign/{businessId}/{userId}")
    public Result assignBusinessUser(@PathVariable Integer businessId,@PathVariable Integer userId){
        businessService.assignBusinessUser(businessId,userId);
        return Result.success();
    }


    //商机添加
    @LogAnno
    @PostMapping
    public Result addBusiness(@RequestBody Business business){
        businessService.addBusiness(business);
        return Result.success();
    }


    //商机列表查询
    @GetMapping
    public Result getBusinessList(BusinessListDTO businessListDTO) {
        PageResult<BusinessListVO> vo=businessService.getBusinessList(businessListDTO);
        return Result.success(vo);
    }
}
